package cc.douquan.com.doutu.delegate;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.OnClick;
import cc.douquan.com.doutu.MyApplication;
import cc.douquan.com.doutu.R;
import cc.douquan.com.doutu.mvp_frame.view.AppDelegate;
import cc.douquan.com.doutu.utils.DataClearManager;
import cc.douquan.com.doutu.utils.ShareUtils;
import cc.douquan.com.doutu.utils.UiHelper;


/**
 * Created by feq on 2016/11/2.
 */

public class MeDelegate extends AppDelegate {
    @Bind(R.id.tv_collection)
    TextView tvCollection;
    @Bind(R.id.tv_catch_size)
    TextView tvCatchSize;
    @Bind(R.id.tv_share)
    TextView tv_share;

    @Override
    public int getRootLayoutId() {
        return R.layout.base_fragment;
    }

    @Override
    public void initWidget() {
        super.initWidget();
    }

    @OnClick({R.id.tv_collection, R.id.rl_clear, R.id.tv_about, R.id.tv_share})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_collection:
                UiHelper.goCollectionActivity(this.getActivity(), null);
                break;
            case R.id.tv_about:
                UiHelper.goAboutActivity(this.getActivity(), null);
                break;
            case R.id.rl_clear:
                new AlertDialog.Builder(this.getActivity()).setTitle("确定要清空缓存？")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                DataClearManager.clearAllCache(MyApplication.getContext());
                                tvCatchSize.setText("0MB");
                            }
                        }).setNegativeButton("取消", null).show();
                break;
            case R.id.tv_share:
                ShareUtils.shareApp(getActivity(), "https://www.pgyer.com/JSND");
                break;
        }
    }

    public void setCatchSize(String size) {
        tvCatchSize.setText(size);
    }
}
